package com.ruoyi.act.module.service.impl;

import com.ruoyi.act.module.domain.ActProcess;
import com.ruoyi.act.module.service.IProcessService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProcessServiceImpl implements IProcessService {

    @Autowired
    private RuntimeService runtimeService;

    @Override
    public ProcessInstance startProcessInstanceByKey(String processDefinitionKey) {
        return runtimeService.startProcessInstanceByKey(processDefinitionKey);
    }

    @Override
    public ProcessInstance startProcessInstanceByKey(ActProcess actProcess) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKeyAndTenantId(
                actProcess.getProcessKey(),
                actProcess.getBusinessKey(),
                actProcess.getVariables(),
                actProcess.getTenantId());
        return processInstance;
    }

    @Override
    public void deleteProcessInstance(String processId, String reason) {
        runtimeService.deleteProcessInstance(processId, reason);
    }

    @Override
    public void suspendProcessInstanceById(String processId) {
        runtimeService.suspendProcessInstanceById(processId);
    }

    @Override
    public void activateProcessInstanceById(String processId) {
        runtimeService.activateProcessInstanceById(processId);
    }
}
